package com.example.tnot.Teacher.MinePart.InternalFragment.collection;

import android.annotation.SuppressLint;
import android.content.res.ColorStateList;
import android.graphics.Color;
import android.os.Bundle;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageButton;

import androidx.viewpager2.widget.ViewPager2;

import com.example.tnot.R;
import com.example.tnot.Teacher.BaseFragment.BaseBackFragment;
import com.example.tnot.Teacher.MinePart.InternalFragment.collection.adapter.vpCollectAdapter;
import com.google.android.material.tabs.TabLayout;
import com.google.android.material.tabs.TabLayoutMediator;

public class collectFragment extends BaseBackFragment {

    ImageButton ib_back;
    ViewPager2 vp_collect;
    TabLayout tab_layout;

    private static final String ARG_PARAM1 = "param1";
    private static final String ARG_PARAM2 = "param2";
    private String mParam1;
    private String mParam2;

    public collectFragment() {

    }

    public static collectFragment newInstance(String param1, String param2) {
        collectFragment fragment = new collectFragment();
        Bundle args = new Bundle();
        args.putString(ARG_PARAM1, param1);
        args.putString(ARG_PARAM2, param2);
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (getArguments() != null) {
            mParam1 = getArguments().getString(ARG_PARAM1);
            mParam2 = getArguments().getString(ARG_PARAM2);
        }
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
     View view = inflater.inflate(R.layout.mine_collect_fragment, container, false);
     ib_back = view.findViewById(R.id.ib_collect_back);
     vp_collect = view.findViewById(R.id.vp_collection);
     tab_layout = view.findViewById(R.id.tab_layout);

     tab_layout.setTabRippleColor(ColorStateList.valueOf(Color.TRANSPARENT));
     vpCollectAdapter adapter = new vpCollectAdapter(getActivity());
     vp_collect.setAdapter(adapter);
        // 将TabLayout与ViewPager2联动
        new TabLayoutMediator(tab_layout, vp_collect,
                (tab, position) -> tab.setText(adapter.tabs[position])
        ).attach();

     ib_back.setOnClickListener(new View.OnClickListener() {
         @Override
         public void onClick(View v) {
             handleBackPressed();
         }
     });
     return view;
    }
}